#ifndef __KERN_FS_IOBUF_H__
#define __KERN_FS_IOBUF_H__

#include <types.h>

/*
 * struct iobuf
 * @io_base: point to the next vacant memory.
 * @io_offset: the offset addr of the object.
 * @io_len: the num of bytes(at least in file system) to be read or write.
 * @io_resid:   the left space after the operation. this parameter can be
 * used to judge if the read or write have operate on io_len bytes or less
 * by comparing it to zero.
 */
struct iobuf {
    void *io_base;
    off_t io_offset;
    size_t io_len;
    size_t io_resid;
};

#define iobuf_used(iob)                         ((size_t)((iob)->io_len - (iob)->io_resid))

struct iobuf *iobuf_init(struct iobuf *iob, void *base, size_t len, off_t offset);
int iobuf_move(struct iobuf *iob, void *data, size_t len, bool m2b, size_t *copiedp);
int iobuf_move_zeros(struct iobuf *iob, size_t len, size_t *copiedp);
void iobuf_skip(struct iobuf *iob, size_t n);

#endif /* !__KERN_FS_IOBUF_H__ */

